import webpack, { Configuration } from 'webpack';
import baseConfig, { isDev } from './base.config';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import CssMinimizerWebpackPlugin from 'css-minimizer-webpack-plugin';
import merge from 'webpack-merge';

const getPlugins = () => {
  let plugins = [];
  if (isDev) {
    plugins = [
      ...plugins,
      new webpack.HotModuleReplacementPlugin(),
      new ReactRefreshWebpackPlugin(),
    ];
  }
  return plugins;
};

const config: Configuration = {
  devtool: isDev && 'eval-cheap-source-map',
  entry: './src/client',
  optimization: {
    minimizer: [new CssMinimizerWebpackPlugin()],
  },
  plugins: getPlugins(),
};

export default merge(baseConfig(true), config);
